<template>
  <div>
    <Header></Header>
    <nav-content></nav-content>
    <Footer></Footer>
  </div>
</template>

<script>
import Header from "../components/Header.vue";
import Footer from "../components/Footer.vue";
import NavContent from "../components/NavContent.vue";
import ajax from "../ajax/ajax";
import { mapMutations } from "vuex";
export default {
  name: "",
  props: [""],
  data() {
    return {};
  },

  components: {
    Header,
    Footer,
    NavContent,
  },

  computed: {},

  beforeMount() {},

  mounted() {},

  methods: {
    ...mapMutations(["updatesUserName"]),
  },

  watch: {},
  /* 进入主页前核验token */
  beforeRouteEnter(to, from, next) {
    // ...
    console.log(to);
    console.log(from);
    next(async (component) => {
      console.log(component);
      let token = localStorage.getItem("token");
      // 得到token后将token发送给服务器的核验接口 进行核验
      let result = await ajax("get", "jwtVerify", { token }, "form");
      console.log(result.user_name);
      console.log(component.updatesUserName);
      // 核验成功之后将用户名存放到vuex的state  result.user_name
      component.updatesUserName(result.user_name);
    });
  },
};
</script>
<style lang='' scoped>
</style>